;;; init-langtool.el --- Configuration for using LanguageTool in Emacs -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:

(with-eval-after-load 'langtool
  (require 'langtool-popup)

  (defun langtool-autoshow-detail-popup (overlays)
    (when (require 'popup nil t)
      ;; Do not interrupt current popup
      (unless (or popup-instances
                  ;; suppress popup after type `C-g` .
                  (memq last-command '(keyboard-quit)))
        (let ((msg (langtool-details-error-message overlays)))
          (popup-tip msg)))))

  ;; Download from https://languagetool.org/download/
  (setq langtool-language-tool-jar (expand-file-name "~/sys/LanguageTool/languagetool-commandline.jar"))
  (setq langtool-language-tool-server-jar (expand-file-name "~/sys/LanguageTool/languagetool-server.jar"))
  (setq langtool-default-language "en-US")
  (setq langtool-java-user-arguments '("-Dfile.encoding=UTF-8"))
  (setq langtool-server-user-arguments '("-p" "8327")))

(global-set-key "\C-x4w" #'langtool-check)
(global-set-key "\C-x4W" #'langtool-check-done)
(global-set-key "\C-x4l" #'langtool-switch-default-language)
(global-set-key "\C-x44" #'langtool-show-message-at-point)
(global-set-key "\C-x4c" #'langtool-correct-buffer)

(provide 'init-langtool)
;;; init-langtool.el ends here
